Skip to content

feat: favorite posts WordPress plugin#78

Open
hahuma wants to merge 2 commits intoApiki:masterfrom
hahuma:petterson-firmino
Open

feat: favorite posts WordPress plugin#78
hahuma wants to merge 2 commits intoApiki:masterfrom
hahuma:petterson-firmino

Conversation

@hahuma
Copy link
Copy Markdown

@hahuma hahuma commented Apr 5, 2026

Summary

  • WordPress plugin implementing favorite posts functionality via WP REST API
  • Custom wp_favorite_posts database table with unique constraint on (user_id, post_id)
  • Three REST API endpoints under apiki-favorites/v1:
    • GET /favorites — list user's favorites (with post titles)
    • POST /favorites — add favorite (201, or 409 if duplicate)
    • DELETE /favorites — remove favorite (200, or 404)
  • TypeScript frontend with heart button injected via the_content filter
  • Toast notifications and loading states for UX feedback
  • Docker setup with WordPress + MySQL for local development

Architecture

Class Responsibility
Plugin Singleton bootstrap, registers all WP hooks
Database Custom table creation (dbDelta), CRUD with $wpdb->prepare()
RestController REST route registration, request handling, auth checks
Assets Script/style enqueue, heart button injection

Security

  • All endpoints require is_user_logged_in()
  • Nonce verification via X-WP-Nonce header
  • Input sanitization with absint()
  • Prepared SQL statements
  • Output escaping in HTML

Test plan

  • Plugin activates and creates database table
  • POST adds favorite, returns 201
  • GET returns favorites with post titles
  • Duplicate POST returns 409 Conflict
  • DELETE removes favorite, returns 200
  • GET after delete returns empty array
  • Unauthenticated requests return 401

hahuma added 2 commits April 4, 2026 23:33
Add REST API plugin for logged-in users to favorite/unfavorite posts
with custom database table persistence.

- Plugin bootstrap with singleton pattern and PSR-4 autoloading
- Custom wp_favorite_posts table with unique constraint on (user_id, post_id)
- REST API endpoints: GET/POST/DELETE on /apiki-favorites/v1/favorites
- TypeScript frontend with heart button, toast notifications
- SCSS styles with hover/active transitions
- Docker setup with WordPress + MySQL for local development
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant